package com.it.travel.handle;

import com.it.travel.vo.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class AllExceptionHandler {

    @ExceptionHandler(Exception.class)
//    @ExceptionHandler(PermissionException.class)
//    @RequestBody
    @ResponseBody
    public Result<?> doException(Exception e) {
        if (e instanceof PermissionException) {
            return Result.error(null, "权限不足");
        }
        e.printStackTrace();
        return Result.error(null, "系统异常");
    }

    @ResponseBody
    @ExceptionHandler(value = PermissionException.class)
    public Result<?> myErrorHandler(PermissionException ex) {
        ex.printStackTrace();
        return Result.error(null, "权限不足");
    }

    @ResponseBody
    @ExceptionHandler(value = TokenValidateFailException.class)
    public Result<?> myErrorHandler(TokenValidateFailException ex) {
        ex.printStackTrace();
        return Result.error(null, "token认证失败");
    }
}